package com.fabriciojf.view;

import com.fabriciojf.util.LogCS;
import java.awt.event.ActionListener;

/**
 *
 * @author fabricio
 * @since 18/03/2010
 * @version 1.1 19/04/2010
 */
public class View extends javax.swing.JFrame {

    private LogCS log;

    /** Creates new form View */
    public View() {
        initComponents();

        /* Associa o botao ao listener  */
        jbtLog.setActionCommand("CMD_LOG");
        jbtLimparLog.setActionCommand("CMD_LIMPARLOG");
        jbtExecutar.setActionCommand("CMD_EXECUTAR");
    }

    /**
     * Listener que devera ser usado pelo controller
     * @param al ActionListener
     */
    public void addActionListener(ActionListener al) {
        jbtLog.addActionListener(al);
        jbtLimparLog.addActionListener(al);
        jbtExecutar.addActionListener(al);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jlStatus = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtLog = new javax.swing.JTextArea();
        jbtFechar = new javax.swing.JToggleButton();
        jbtLimparLog = new javax.swing.JButton();
        jbtLog = new javax.swing.JButton();
        jbtExecutar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Calima Update 2.1.0 - Projetus Informática ... ");

        jLabel1.setText("Processo de Atualização Calima-Update");

        jlStatus.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jlStatus.setText("...");

        jtLog.setColumns(20);
        jtLog.setRows(5);
        jScrollPane1.setViewportView(jtLog);

        jbtFechar.setText("Fechar");
        jbtFechar.setEnabled(false);
        jbtFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtFecharActionPerformed(evt);
            }
        });

        jbtLimparLog.setText("Limpar Log");

        jbtLog.setText("Mostrar Conteúdo do arquivo de log");

        jbtExecutar.setText("Executar Novamente");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jbtLimparLog)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtLog)
                .addGap(18, 18, 18)
                .addComponent(jbtExecutar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                .addComponent(jbtFechar)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 570, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtFechar)
                    .addComponent(jbtLog)
                    .addComponent(jbtLimparLog)
                    .addComponent(jbtExecutar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 369, Short.MAX_VALUE)
                        .addComponent(jlStatus)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jlStatus))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Torna a view invisivel
     * @param evt
     */
    private void jbtFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtFecharActionPerformed
        this.dispose();
    }//GEN-LAST:event_jbtFecharActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new View().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtExecutar;
    private javax.swing.JToggleButton jbtFechar;
    private javax.swing.JButton jbtLimparLog;
    private javax.swing.JButton jbtLog;
    private javax.swing.JLabel jlStatus;
    private javax.swing.JTextArea jtLog;
    // End of variables declaration//GEN-END:variables

    /**
     * Mostra a informação na tela
     */
    public void setStatus(String status) {
        jlStatus.setText(status + " ...");
        setLog(status);
    }

    /**
     * Mostra a informação no log
     */
    public void setLog(String status) {
        jtLog.append(status + " ...\n");
    }

    public void jbtEnabled() {
        jbtFechar.setEnabled(true);
    }

    /**
     * @param log the log to set
     */
    public void setLog(LogCS log) {
        this.log = log;
    }
}
